// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //菜单栏图片
    imgList: ['/imgs/classify1.png', '/imgs/classify2.png', '/imgs/home1.png','/imgs/list1.png'],
    navList: [{
        'src': '/imgs/shop.png',
        'title': '社区商城',
        'content':'桥头社区特色商品',
        'pagePath': '/packageA/pages/shop/shop',
      },
     
      {
        'src': '/imgs/activity.png',
        'title': '社区活动',
        'content':'桥头社区活动报名',
        'pagePath': '/packageB/pages/activity/activity'
      },
    ],
    activities:[
      {id:1,title:'运动','src': 'https://ts1.cn.mm.bing.net/th/id/R-C.2ea6da0b086bfcfc24c2ab3dd236b953?rik=uXT261db1fQjGw&riu=http%3a%2f%2fwww.new-sports.cn%2fquanminjianshen%2f202005%2fW020200519403588919159.jpg&ehk=rL0fwoSXysdthF86D8UYV3cBgoDkSYdMFoPZppdzoeA%3d&risl=&pid=ImgRaw&r=0',},
      {id:2,title:'晚会','src': 'https://ts1.cn.mm.bing.net/th/id/R-C.54031165c82295bc50f9500b2e44e92d?rik=WniqFZ%2b5gPjX2Q&riu=http%3a%2f%2fimg0.xinmin.cn%2f2020%2f09%2f29%2f20200929105432479567.png&ehk=7VI0FA0fOckqCi5yUwQoSLLWEnJAf0UXbFA%2frVhOHBE%3d&risl=&pid=ImgRaw&r=0',},
      {id:3,title:'观影','src': 'https://img.rednet.cn/2022/08-01/6d651d4f-0564-428b-bb1d-13f6939f8f3e.png',},
    ],
    listData: [
      // { id: 1, title: '活动标题1' },
      // { id: 2, title: '活动标题2' },
      // { id: 3, title: '活动标题3' },
      // ...更多活动数据
    ],

    //存放轮播图数据的列表
    // swiperList:{}
    swiperList:[
      // {src:'https://pic.ibaotu.com/00/03/92/15j888piCQzY.jpg-1.jpg!ww7002'},
      // {src:'https://tse2-mm.cn.bing.net/th/id/OIP-C.u20dQatPEAuehJvGongWIgHaDe?rs=1&pid=ImgDetMain'},
    ],
  },
  navClick: function(event) {
    const item = event.currentTarget.dataset.item;
    wx.navigateTo({
      url: item.pagePath
    });
  },
//  请求资讯
onLoad:function() {
  this.fetchEvents();
  
  this.getSwiperList();
},
// 获取资讯列表
fetchEvents: function() {
  var that=this;
  const apiUrl = 'http://8.138.155.196:3000/users/api/listDate'; // 替换为实际的API URL
  wx.request({
    url: apiUrl,
    method: 'GET',
    success: (res) => {
      if (res.statusCode === 200 && res.data) {
        that.setData({
          listData: res.data.data
        });
        console.log(res.data);
      } else {
        console.error('Failed to fetch events:', res);
      }
    },
    fail: (err) => {
      console.error('Request failed:', err);
    }
  });
},
  

  //获取轮播图数据的方法
  getSwiperList :function(){
    wx.request({
      url: 'http://8.138.155.196:3000/users/api/communitypicture',
      method:'GET',
      success:(res)=>{
        console.log(res)
        this.setData({
          swiperList:res.data.data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    var that = this;
        wx.getSystemInfo({
            success(res) {
                that.setData({
                    viewHeight:res.windowHeight
                })
            }
        })
  },
  goToDetail: function(e) {
    // 获取点击的列表项的id
    const id = e.currentTarget.dataset.id;
    // 根据id进行页面跳转，这里假设有一个详情页面叫detail
    wx.navigateTo({
      url: `/pages/articleDetail/articleDetails?id=${id}`
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})